package com.sunqizhong.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sunqizhong.entity.Clazz;
import com.sunqizhong.entity.ClazzsQueryParam;
import com.sunqizhong.entity.PageBean;
import com.sunqizhong.mapper.ClazzsMapper;
import com.sunqizhong.service.ClazzsService;
import jdk.jshell.execution.JdiExecutionControlProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClazzsServiceImpi implements ClazzsService {
    @Autowired
    private ClazzsMapper clazzsMapper;

    /*
    * 分页列表查询
    * */
    @Override
    public PageBean page(ClazzsQueryParam param) {
        PageHelper.startPage(param.getPage(), param.getPageSize());
        List<Clazz> ClazzsList = clazzsMapper.list(param);
        Page p = (Page) ClazzsList;
        return new PageBean(p.getTotal(),p.getResult());
    }

    /*
    * 增加班级
    * */
    @Override
    public void add(Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        clazzsMapper.add(clazz);
    }

    /*
    * 根据id查询班级信息
    * */
    @Override
    public Clazz getInfo(Integer id) {
        return clazzsMapper.getById(id);
    }

    /*
    * 修改班级
    * */
    @Override
    public void update(Clazz clazz) {
        clazz.setUpdateTime(LocalDateTime.now());
        clazzsMapper.update(clazz);
    }

    /*
    * 删除班级
    * */
    @Override
    public void delete(Integer id) {
        Integer deleted = clazzsMapper.delete(id);
        System.out.println("删除的数据结果为：" + deleted);
        clazzsMapper.delete(id);
    }

/*    @Override
    public List<Clazz> list() {
        return clazzsMapper.selectAll();
    }*/
}
